package com.restart.game.common.reptile;

import com.restart.game.common.bean.HtmlBean;
import com.restart.game.common.util.search.CrawlText;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ReStartLin
 * @data 2018/12/24 17:03
 * @classDesc: 功能描述:
 */
public class Reptile97973 {
    public static String baseUrl = "http://search.97973.com/guides/search";
    public static final String C_NODE = ".hot_con a[href$=.shtml]";
    public static final String C_TITLE_NODE = ".CONTENT .LEFT h1";
    public static final String C_HTML_NODE = ".CONTENT .LEFT #fonttext";

    public static List<HtmlBean> searchAll(String fileName, String searchTitle, int pageCount) throws IOException {
        String[] docs = {
                C_NODE, //子连接节点
                C_TITLE_NODE,        //title节点
                C_HTML_NODE ,//文章节点
                searchTitle,                 //标题
                fileName  //type
        };
        List<HtmlBean> all = new ArrayList<>();
        int index = 1;
        while (index <= pageCount) {
            String url = baseUrl + "?search_key=" + searchTitle + "&page=" + index;
            List<HtmlBean> text = CrawlText.getText(url, docs);
            all.addAll(text);
            //序列化
            index++;
        }
        return all;
    }


    public static String getHtml(String url) throws IOException {
        return CrawlText.getText2Child(url, new String[]{C_HTML_NODE});
    }
}
